package com.itheima.thread.dead.demo01;

public class DeadThread extends Thread {

    private boolean flag;

    public DeadThread(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        if (flag) {
            synchronized (MyLock.R1) {
                System.out.println(Thread.currentThread().getName() + "获取到了R1 , 申请R2锁......");
                synchronized (MyLock.R2) {
                    System.out.println(Thread.currentThread().getName() + "获取到了R1 , 获取到了R2锁......");
                }
            }
        } else {
            synchronized (MyLock.R2) {
                System.out.println(Thread.currentThread().getName() + "获取到了R2 , 申请R1锁......");
                synchronized (MyLock.R1) {
                    System.out.println(Thread.currentThread().getName() + "获取到了R2 , 获取到了R1锁......");
                }
            }
        }
    }
}
